function	showComment(id)
{
	$$$("cms-" + id).style.display = 'none';
	$$$("cm-" + id).style.display = '';
	$$$("avatar-" + id).style.display = '';
	$$$("img-" + id).style.visibility = 'visible';
	$$$("submit-" + id).style.display = '';
	$$$("cm-" + id).focus();
}

function	hideComment(id)
{
	$$$("cms-" + id).style.display = '';
	$$$("cm-" + id).style.display = 'none';
	$$$("avatar-" + id).style.display = 'none';
	$$$("img-" + id).style.visibility = 'hidden';	
	$$$("submit-" + id).style.display = 'none';			
}

function more(topic)
{
	$$$("more-" + topic).innerHTML = "<img src='/images/bok-loader.gif' />";

			var	query	=	"act=more_reply&bok=dd&topic="+topic;
			var http 	=	khoitao_ajax();
			try
			{
				http.open("POST", "/action/the-gioi-phang.html");
				http.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
				http.setRequestHeader("Cache-control", "no-cache");		
				http.onreadystatechange = function()
				{
					if (http.readyState == 4)
					{
						if (http.status == 200)
						{
							
							x = http.responseText;
							$$$("treply-" + topic).innerHTML = x;

						}
						else
						{
								return false;
						}
					}
				}
				http.send(query);
			}
			catch (e)
			{
			}
			return false;
}

function new_reply(id,new_rep)
{
	noi_dung = new_rep.noi_dung.value;
	var len = noi_dung.length;
	if ( len > 1000 )
	{
		$.jGrowl("Nội dung bình luận quá dài!");
	}
	else
	{
		$$$("noi_dung-" + id).innerHTML = "<img src='/images/bok-loader.gif' />";
		
		if(!noi_dung)
		{
			$.jGrowl("Vui lòng nhập nội dung!");
			new_rep.noi_dung.focus();
			return false;
		}
		else
		{
			var	query	=	"act=new_reply&bok=dd&topic="+id+"&noi_dung="+noi_dung;
			var http 	=	khoitao_ajax();
			try
			{
				http.open("POST", "/action/the-gioi-phang.html");
				http.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
				http.setRequestHeader("Cache-control", "no-cache");		
				http.onreadystatechange = function()
				{
					if (http.readyState == 4)
					{
						if (http.status == 200)
						{
							
							x = http.responseText.split("|");
							if (x[0] != "OK")
							{
								$.jGrowl(x);
							}
							else
							{
								$$$("treply-" + id).innerHTML += x[1];
								$$$("new_rep-" + id).style.display = "none";
							}
						}
						else
						{
								return false;
						}
					}
				}
				http.send(query);
			}
			catch (e)
			{
			}
			return false;
		}
	}
}

function new_album(newalbum)
{
	type = newalbum.type.value;
	title = newalbum.ten_album.value;
	noi_dung = newalbum.chu_thich_album.value;
	cat = newalbum.cat.value;

	if (title == "" || title == null) 
	{
		$.jGrowl("Vùi lòng nhập Tên Album!");
		return false;
	}

	new_html = $$$("new_topic").innerHTML;
	$$$("new_topic").innerHTML = "<center><img src='/images/bok-loader.gif' /></center>";	
	
		var	query	=	"act=new_topic&bok=dd&cat="+cat+"&type="+type+"&title="+title+"&noi_dung="+noi_dung;
		var http 	=	khoitao_ajax();
		try
		{
			http.open("POST", "/action/the-gioi-phang.html");
			http.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			http.setRequestHeader("Cache-control", "no-cache");		
			http.onreadystatechange = function()
			{
				if (http.readyState == 4)
				{
					if (http.status == 200)
					{						
						x = http.responseText.split("|");
						if (x[0] != "OK")
						{
							$.jGrowl(x);
							$$$("new_topic").innerHTML = new_html;
						}
						else
						{
							window.location.href = x[1];
						}
					}
					else
					{
							return false;
					}
				}
			}
			http.send(query);
		}
		catch (e)
		{
		}
		return false;
}

function new_topic(new_pic)
{
<!--	alert(nicEditors.findEditor('noi_dung').getContent()); -->

	type = new_pic.type.value;
	if ( type == "note" ) 
	{
		title = new_pic.title.value;
		noi_dung = nicEditors.findEditor('noi_dung_bai_viet').getContent();
		limit = 100000;
		if (title == "" || title == null) 
		{
			$.jGrowl("Vùi lòng nhập Tiêu đề bài viết!");
			return false;
		}
	}
	else if ( type == "photo_link" ) 
	{
		title = new_pic.link_photo.value;
		noi_dung = new_pic.binh_luan_hinh_anh.value;
		limit = 5000;
		if (title == "" || title == null) 
		{
			$.jGrowl("Vùi lòng nhập Đường dẫn hình ảnh!");
			return false;
		}
	}
	else if ( type == "photo_album" ) 
	{
		title = new_pic.ten_album.value;
		noi_dung = new_pic.chu_thich_album.value;
		limit = 5000;
		if (title == "" || title == null) 
		{
			$.jGrowl("Vùi lòng nhập Tên album!");
			return false;
		}
	}
	else
	{
		title = 'no';
		noi_dung = new_pic.noi_dung.value; 
		limit = 5000;
		if (noi_dung == "" || noi_dung == "Bạn đang nghĩ gì ... ") 
		{
			$.jGrowl("Vùi lòng nhập nội dung!");
			return false;
		}
	}
	cat = new_pic.cat.value;
	
	var len = noi_dung.length;
	if ( len > limit )
	{
		$.jGrowl("Nội dung quá dài!");
		return false;
	}
	else
	{	
	new_html = $$$("new_topic").innerHTML;
	$$$("new_topic").innerHTML = "<center><img src='/images/bok-loader.gif' /></center>";	

		if(!noi_dung)
		{
			$.jGrowl("Vui lòng nhập nội dung!");
			new_pic.noi_dung.focus();
			return false;
		}
		else
		{
			var	query	=	"act=new_topic&bok=dd&cat="+cat+"&type="+type+"&title="+title+"&noi_dung="+encodeURIComponent(noi_dung);
			var http 	=	khoitao_ajax();
			try
			{
				http.open("POST", "/action/the-gioi-phang.html");
				http.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
				http.setRequestHeader("Cache-control", "no-cache");		
				http.onreadystatechange = function()
				{
					if (http.readyState == 4)
					{
						if (http.status == 200)
						{
							
							x = http.responseText.split("|");
							if (x[0] != "OK")
							{
								$.jGrowl(x);
								$$$("new_topic").innerHTML = new_html;
							}
							else
							{
								$$$("bok").innerHTML =x[1]+$$$("bok").innerHTML;
								$$$("new_topic").innerHTML = new_html;
							}
						}
						else
						{
								return false;
						}
					}

				}
				http.send(query);
			}
			catch (e)
			{
			}
			return false;
		}
	}
}

function like_topic(topic)
{
		$toolt = $$$("toolt-" + topic).innerHTML;
		$$$("toolt-" + topic).innerHTML = "<img src='/images/bok-loader.gif' />";
	
		var	query	=	"act=like_topic&bok=dd&topic="+topic;
		var http 	=	khoitao_ajax();
		try
		{
			http.open("POST", "/action/the-gioi-phang.html");
			http.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			http.setRequestHeader("Cache-control", "no-cache");		
			http.onreadystatechange = function()
			{
				if (http.readyState == 4)
				{
					if (http.status == 200)
					{
						
						x = http.responseText;
						if (x != "OK")
						{
							$.jGrowl(x);
							$$$("toolt-" + topic).innerHTML = $toolt;
						}
						else
						{
							$toolt = $toolt.replace('like', 'unlike');
							$toolt = $toolt.replace('Like', 'Unlike');							
							$$$("toolt-" + topic).innerHTML = $toolt;
							if ( (!$$$("like_topic-" + topic)) || ($$$("like_topic-" + topic).style.display == 'none') )
							{
								$reply_topic = "<div class=like id=like_topic-" + topic + "> Có <span id=clike_topic-"+topic+">1</span> người thích</div>" ;
								$$$("treply-" + topic).innerHTML = $reply_topic + $$$("treply-" + topic).innerHTML;								
							}
							else
							{
								$$$("clike_topic-" + topic).innerHTML = parseInt($$$("clike_topic-" + topic).innerHTML) + 1;
							}
						}
					}
					else
					{
							return false;
					}
				}
			}
			http.send(query);
		}
		catch (e)
		{
		}
		return false;
}

function unlike_topic(topic)
{
		$toolt = $$$("toolt-" + topic).innerHTML;
		$$$("toolt-" + topic).innerHTML = "<img src='/images/bok-loader.gif' />";
	
		var	query	=	"act=unlike_topic&bok=dd&topic="+topic;
		var http 	=	khoitao_ajax();
		try
		{
			http.open("POST", "/action/the-gioi-phang.html");
			http.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			http.setRequestHeader("Cache-control", "no-cache");		
			http.onreadystatechange = function()
			{
				if (http.readyState == 4)
				{
					if (http.status == 200)
					{
						
						x = http.responseText;
						if (x != "OK")
						{
							$.jGrowl(x);
						}
						else
						{
							$toolt = $toolt.replace('unlike', 'like');
							$toolt = $toolt.replace('Unlike', 'Like');							
							$$$("toolt-" + topic).innerHTML = $toolt;
							if ( parseInt($$$("clike_topic-" + topic).innerHTML) == 1 ) 
							{
								$$$("like_topic-" + topic).style.display = 'none';
							}
							else
							{
								$$$("clike_topic-" + topic).innerHTML = parseInt($$$("clike_topic-" + topic).innerHTML) - 1;
							}
							
						}
					}
					else
					{
							return false;
					}
				}
			}
			http.send(query);
		}
		catch (e)
		{
		}
		return false;
}

function del_topic(topic)
{
	
	var a = confirm("Bạn có thật sự muốn xóa?");
	if (a) 
	{
		$$$("topic-"+topic).style.display = 'none';
		var	query	=	"act=del_topic&bok=dd&topic="+topic;
		var http 	=	khoitao_ajax();
		try
		{
			http.open("POST", "/action/the-gioi-phang.html");
			http.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			http.setRequestHeader("Cache-control", "no-cache");		
			http.onreadystatechange = function()
			{
				if (http.readyState == 4)
				{
					if (http.status == 200)
					{
						
						x = http.responseText;
						if (x != "OK")
						{
							$.jGrowl(x);
						}
						else
						{
						}
					}
					else
					{
							return false;
					}
				}
			}
			http.send(query);
		}
		catch (e)
		{
		}
		return false;
	}
}

function like_reply(reply)
{
		$toolr = $$$("toolr-" + reply).innerHTML;
		$$$("toolr-" + reply).innerHTML = "<img src='/images/bok-loader.gif' />";
		
		var	query	=	"act=like_reply&bok=dd&reply="+reply;
		var http 	=	khoitao_ajax();
		try
		{
			http.open("POST", "/action/the-gioi-phang.html");
			http.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			http.setRequestHeader("Cache-control", "no-cache");		
			http.onreadystatechange = function()
			{
				if (http.readyState == 4)
				{
					if (http.status == 200)
					{
						
						x = http.responseText;
						if (x != "OK")
						{
							$.jGrowl(x);
							$$$("toolr-" + reply).innerHTML = $toolr ;
						}
						else
						{
							$toolr = $toolr.replace('like', 'unlike');
							$toolr = $toolr.replace('Like', 'Unlike');							
							$$$("toolr-" + reply).innerHTML = $toolr;
							if ( (!$$$("like_reply-" + reply)) || ($$$("like_reply-" + reply).style.display == 'none') )
							{
								$toolr = '<a onclick="javascript:like_reply('+reply+');" style="cursor: pointer;">Unlike</a> · <span id ="like_reply-'+reply+'"><img src="/images/s_like.png" border=0  align="top"> <span id="clike_reply"> 1 </span> người</span>';
								$$$("toolr-" + reply).innerHTML = $toolr;								
							}
							else
							{
								$$$("clike_reply-" + reply).innerHTML = parseInt($$$("clike_reply-" + reply).innerHTML) + 1;
							}							
						}
					}
					else
					{
							return false;
					}
				}
			}
			http.send(query);
		}
		catch (e)
		{
		}
		return false;
}

function unlike_reply(reply)
{

		$toolr = $$$("toolr-" + reply).innerHTML;
		$$$("toolr-" + reply).innerHTML = "<img src='/images/bok-loader.gif' />";
	
		var	query	=	"act=unlike_reply&bok=dd&reply="+reply;
		var http 	=	khoitao_ajax();
		try
		{
			http.open("POST", "/action/the-gioi-phang.html");
			http.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			http.setRequestHeader("Cache-control", "no-cache");		
			http.onreadystatechange = function()
			{
				if (http.readyState == 4)
				{
					if (http.status == 200)
					{
						
						x = http.responseText;
						if (x != "OK")
						{
							$.jGrowl(x);
						}
						else
						{
							$toolr = $toolr.replace('unlike', 'like');
							$toolr = $toolr.replace('Unlike', 'Like');							
							$$$("toolr-" + reply).innerHTML = $toolr;
							if ( parseInt($$$("clike_reply-" + reply).innerHTML) == 1 ) 
							{
								$$$("like_reply-" + reply).style.display = 'none';
							}
							else
							{
								$$$("clike_reply-" + reply).innerHTML = parseInt($$$("clike_reply-" + reply).innerHTML) - 1;
							}							
						}
					}
					else
					{
							return false;
					}
				}
			}
			http.send(query);
		}
		catch (e)
		{
		}
		return false;
}

function del_reply(reply)
{
		
	var a = confirm("Bạn có thật sự muốn xóa?");
	if (a) 
	{
		$$$("reply-" + reply).style.display = 'none';

		var	query	=	"act=del_reply&bok=dd&reply="+reply;
		var http 	=	khoitao_ajax();
		try
		{
			http.open("POST", "/action/the-gioi-phang.html");
			http.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			http.setRequestHeader("Cache-control", "no-cache");		
			http.onreadystatechange = function()
			{
				if (http.readyState == 4)
				{
					if (http.status == 200)
					{
						
						x = http.responseText;
						if (x != "OK")
						{
							$.jGrowl(x);
						}
						else
						{
							return false;
						}
					}
					else
					{
							return false;
					}
				}
			}
			http.send(query);
		}
		catch (e)
		{
		}
		return false;
	}
}

function new_photo(topic,filename)
{
		var	query	=	"act=new_photo&bok=dd&topic="+topic+"&filename="+filename;
		var http 	=	khoitao_ajax();
		try
		{
			http.open("POST", "/action/");
			http.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			http.setRequestHeader("Cache-control", "no-cache");		
			http.onreadystatechange = function()
			{
				if (http.readyState == 4)
				{
					if (http.status == 200)
					{
						
						x = http.responseText.split("|");
						if (x[0] != "OK")
						{
							$.jGrowl(x);
						}
						else
						{
							$$$("album").innerHTML += x[1];
						}
					}
					else
					{
						return false;
					}
				}
			}
			http.send(query);
		}
		catch (e)
		{
		}
		return false;

}

function del_photo(topic,filename)
{
	var a = confirm("Bạn có thật sự muốn xóa?");
	if (a) 
	{
		$$$(filename).style.display = 'none';
		var	query	=	"act=del_photo&bok=dd&topic="+topic+"&filename="+filename;
		var http 	=	khoitao_ajax();
		try
		{
			http.open("POST", "/action/");
			http.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			http.setRequestHeader("Cache-control", "no-cache");		
			http.onreadystatechange = function()
			{
				if (http.readyState == 4)
				{
					if (http.status == 200)
					{
						x = http.responseText;
						if (x != "OK")
						{
							$.jGrowl(x);
						}
						else
						{
							return false;
						}
					}
					else
					{
						return false;
					}
				}
			}
			http.send(query);
		}
		catch (e)
		{
		}
		return false;
	}
}

function edit_topic(topic)
{
	title = edit_2pic.title.value;
	noi_dung = nicEditors.findEditor('noi_dung_bai_viet').getContent();
	if (title == "" || title == null) 
	{
		$.jGrowl("Vùi lòng nhập Tiêu đề bài viết!");
		return false;
	}

	new_html = $$$("form_edit").innerHTML;
	$$$("form_edit").innerHTML = "<center><img src='/images/bok-loader.gif' /></center>";	

	if(!noi_dung)
	{
		$.jGrowl("Vui lòng nhập nội dung!");
		edit_2pic.noi_dung.focus();
		return false;
	}
	else
	{
		var	query	=	"act=edit_topic&topic="+topic+"&title="+title+"&noi_dung="+encodeURIComponent(noi_dung);
		var http 	=	khoitao_ajax();
		try
		{
			http.open("POST", "/action/");
			http.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			http.setRequestHeader("Cache-control", "no-cache");		
			http.onreadystatechange = function()
			{
				if (http.readyState == 4)
				{
					if (http.status == 200)
					{
						x = http.responseText;
						if (x != "OK")
						{
							$.jGrowl(x);
							$$$("form_edit").innerHTML = new_html;
							edit_2pic.title.value = title;
						}
						else
						{
							window.location.reload();
						}
					}
					else
					{
						return false;
					}
				}
			}
			http.send(query);
		}
		catch (e)
		{
		}
		return false;
	}
}

